package cn.edu.nwafu.hjpg.service.impl;

import cn.edu.nwafu.hjpg.dao.ElementDao;
import cn.edu.nwafu.hjpg.entity.Element;
import cn.edu.nwafu.hjpg.service.ElementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ElementServiceImpl implements ElementService {
    Logger logger = LoggerFactory.getLogger(ElementService.class);
    final ElementDao elementDao;
    public ElementServiceImpl(ElementDao elementDao) {
        this.elementDao = elementDao;
    }

    @Override
    public List<Object> findAll() {
        return null;
    }

    @Override
    public Page<?> findByPageLike(String keyword,String type, Pageable pageable) {

        return elementDao.findElementsByBaseinfoTypeAndBaseinfoCasLikeOrBaseinfoZwmcLikeOrBaseinfoWzbmLike(type,keyword,keyword,keyword,pageable);

    }

    @Override
    public Page<?> findByType(String type,String keyword, Pageable pageable) {
        return elementDao.findAllByBaseinfoTypeAndBaseinfoWzbmLikeOrBaseinfoCasLike(type,keyword,keyword,pageable);
    }

    @Override
    public String addElement(Element element) {
        return elementDao.insert(element).getBaseinfoWzbm();
    }

    @Override
    public String updateElement(Element element) {
        return elementDao.save(element).getBaseinfoWzbm();
    }

    @Override
    public void delElement(Element element) {
        elementDao.deleteElementByBaseinfoWzbm(element.getId());
    }

    @Override
    public Element findById(String id) {
        return elementDao.findElementByBaseinfoWzbm(id);
    }

    @Override
    public List<Element> findAllByCasNo(String casNo) {
        return elementDao.findAllByBaseinfoCas(casNo);
    }


}
